home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-10-15 | 1.3 KB | 49 lines | [TEXT/MMCC] |
- //
- // TextUtilities
- // ©1994 Chris K. Thomas. All Rights Reserved.
- //
- // These will probably be incorporated as
- // TzuTool utiltity callbacks.
- //
- // InsertText written Oct 12 or 13 94 <ckt>
- // DeleteText written Oct 13 or 14 94 <ckt>
-
- #include "TzuTextUtils.h"
- #include <Memory.h>
-
- pascal void InsertText(Handle hText,long insertOffset,long insertLen,const void *insert)
- {
- long hTextLen = GetHandleSize(hText);
- char hTextState = HGetState(hText);
- Ptr localText = NULL;
-
- // SetHandleSize might need to move the memory to resize it
- // which it can't do if the handle is locked
- HUnlock(hText);
- SetHandleSize(hText,hTextLen + insertLen);
- if(MemError()!=noErr) return;
-
- HLockHi(hText);
- localText = *hText;
-
- BlockMoveData(&localText[insertOffset],&localText[insertOffset+insertLen],hTextLen - insertOffset);
- BlockMoveData(insert,&localText[insertOffset],insertLen);
-
- HSetState(hText,hTextState);
- }
-
- pascal void DeleteText(Handle hText,long offsetToText,long textLen)
- {
- long hTextLen = GetHandleSize(hText);
- char hTextState = HGetState(hText);
- Ptr localText = NULL;
-
- localText = *hText;
-
- BlockMoveData(&localText[offsetToText+textLen],&localText[offsetToText],hTextLen - (offsetToText+textLen));
- HUnlock(hText);
- SetHandleSize(hText,hTextLen - textLen);
- HLockHi(hText);
-
- HSetState(hText,hTextState);
- }